home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / boekhoud / finan / BADGER finance v1.0 beta 2.exe / xampplite / phpMyAdmin / db_datadict.php < prev    next >
PHP Script  |  2006-01-17  |  9KB  |  299 lines

  1. <?php
  2. /* $Id: db_datadict.php,v 2.23 2006/01/17 17:02:28 cybot_tm Exp $ */
  3.  
  4.  
  5. /**
  6.  * Gets the variables sent or posted to this script, then displays headers
  7.  */
  8. require_once('./libraries/common.lib.php');
  9.  
  10. if (!isset($selected_tbl)) {
  11.     require_once('./libraries/header.inc.php');
  12. }
  13.  
  14.  
  15. /**
  16.  * Gets the relations settings
  17.  */
  18. require_once('./libraries/relation.lib.php');
  19. require_once('./libraries/transformations.lib.php');
  20.  
  21. $cfgRelation  = PMA_getRelationsParam();
  22.  
  23. /**
  24.  * Check parameters
  25.  */
  26. PMA_checkParameters(array('db'));
  27.  
  28. /**
  29.  * Defines the url to return to in case of error in a sql statement
  30.  */
  31. if (isset($table)) {
  32.     $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
  33. } else {
  34.     $err_url = 'db_details.php?' . PMA_generate_common_url($db);
  35. }
  36.  
  37. if ($cfgRelation['commwork']) {
  38.     $comment = PMA_getComments($db);
  39.  
  40.     /**
  41.      * Displays DB comment
  42.      */
  43.     if (is_array($comment)) {
  44.         ?>
  45.     <p> <?php echo $strDBComment; ?> 
  46.         <i><?php echo htmlspecialchars( implode( ' ', $comment ) ); ?></i></p>
  47.         <?php
  48.     } // end if
  49. }
  50.  
  51. /**
  52.  * Selects the database and gets tables names
  53.  */
  54. PMA_DBI_select_db($db);
  55. $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
  56.  
  57. $count  = 0;
  58. while ($row = PMA_DBI_fetch_assoc($rowset)) {
  59.     $myfieldname = 'Tables_in_' . htmlspecialchars($db);
  60.     $table        = $row[$myfieldname];
  61.     if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  62.         $comments = PMA_getComments($db, $table);
  63.     }
  64.  
  65.     if ($count != 0) {
  66.         echo '<div style="page-break-before: always;">' . "\n";
  67.     } else {
  68.         echo '<div>' . "\n";
  69.     }
  70.  
  71.     echo '<h2>' . $table . '</h2>' . "\n";
  72.  
  73.     /**
  74.      * Gets table informations
  75.      */
  76.     // The 'show table' statement works correct since 3.23.03
  77.     $showtable    = PMA_DBI_get_tables_full( $db, $table );
  78.     $num_rows     = (isset($showtable[$table]['TABLE_ROWS']) ? $showtable[$table]['TABLE_ROWS'] : 0);
  79.     $show_comment = (isset($showtable[$table]['TABLE_COMMENT']) ? $showtable[$table]['TABLE_COMMENT'] : '');
  80.     unset( $showtable );
  81.  
  82.  
  83.     /**
  84.      * Gets table keys and retains them
  85.      */
  86.  
  87.     PMA_DBI_select_db($db);
  88.     $result       = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
  89.     $primary      = '';
  90.     $indexes      = array();
  91.     $lastIndex    = '';
  92.     $indexes_info = array();
  93.     $indexes_data = array();
  94.     $pk_array     = array(); // will be use to emphasis prim. keys in the table
  95.                              // view
  96.     while ($row = PMA_DBI_fetch_assoc($result)) {
  97.         // Backups the list of primary keys
  98.         if ($row['Key_name'] == 'PRIMARY') {
  99.             $primary   .= $row['Column_name'] . ', ';
  100.             $pk_array[$row['Column_name']] = 1;
  101.         }
  102.         // Retains keys informations
  103.         if ($row['Key_name'] != $lastIndex ){
  104.             $indexes[] = $row['Key_name'];
  105.             $lastIndex = $row['Key_name'];
  106.         }
  107.         $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
  108.         $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
  109.         if (isset($row['Cardinality'])) {
  110.             $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  111.         }
  112.         // I don't know what does following column mean....
  113.         // $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
  114.  
  115.         $indexes_info[$row['Key_name']]['Comment']     = $row['Comment'];
  116.  
  117.         $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
  118.         if (isset($row['Sub_part'])) {
  119.             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  120.         }
  121.  
  122.     } // end while
  123.     if ($result) {
  124.         PMA_DBI_free_result($result);
  125.     }
  126.  
  127.  
  128.     /**
  129.      * Gets fields properties
  130.      */
  131.     $result      = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
  132.     $fields_cnt  = PMA_DBI_num_rows($result);
  133.     // Check if we can use Relations (Mike Beck)
  134.     if (!empty($cfgRelation['relation'])) {
  135.         // Find which tables are related with the current one and write it in
  136.         // an array
  137.         $res_rel = PMA_getForeigners($db, $table);
  138.  
  139.         if (count($res_rel) > 0) {
  140.             $have_rel = TRUE;
  141.         } else {
  142.             $have_rel = FALSE;
  143.         }
  144.     } else {
  145.         $have_rel = FALSE;
  146.     } // end if
  147.  
  148.  
  149.     /**
  150.      * Displays the comments of the table if MySQL >= 3.23
  151.      */
  152.     if (!empty($show_comment)) {
  153.         echo $strTableComments . ': ' . $show_comment . '<br /><br />';
  154.     }
  155.  
  156.     /**
  157.      * Displays the table structure
  158.      */
  159.     ?> 
  160.  
  161. <table width="100%" class="print">
  162. <tr><th width="50"><?php echo $strField; ?></th>
  163.     <th width="80"><?php echo $strType; ?></th>
  164. <?php /*    <th width="50"><?php echo $strAttr; ?></th>*/ ?>
  165.     <th width="40"><?php echo $strNull; ?></th>
  166.     <th width="70"><?php echo $strDefault; ?></th>
  167. <?php /*    <th width="50"><?php echo $strExtra; ?></th>*/ ?>
  168.     <?php
  169.     if ($have_rel) {
  170.         echo '    <th>' . $strLinksTo . '</th>' . "\n";
  171.     }
  172.     if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  173.         echo '    <th>' . $strComments . '</th>' . "\n";
  174.     }
  175.     if ($cfgRelation['mimework']) {
  176.         echo '    <th>MIME</th>' . "\n";
  177.     }
  178.     ?>
  179. </tr>
  180.     <?php
  181.     $odd_row = true;
  182.     while ($row = PMA_DBI_fetch_assoc($result)) {
  183.  
  184.         $type             = $row['Type'];
  185.         // reformat mysql query output - staybyte - 9. June 2001
  186.         // loic1: set or enum types: slashes single quotes inside options
  187.         if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
  188.             $tmp[2]       = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
  189.             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  190.             $type_nowrap  = '';
  191.  
  192.             $binary       = 0;
  193.             $unsigned     = 0;
  194.             $zerofill     = 0;
  195.         } else {
  196.             $binary       = stristr($row['Type'], 'binary');
  197.             $unsigned     = stristr($row['Type'], 'unsigned');
  198.             $zerofill     = stristr($row['Type'], 'zerofill');
  199.             $type_nowrap  = ' nowrap="nowrap"';
  200.             $type         = preg_replace('@BINARY@i', '', $type);
  201.             $type         = preg_replace('@ZEROFILL@i', '', $type);
  202.             $type         = preg_replace('@UNSIGNED@i', '', $type);
  203.             if (empty($type)) {
  204.                 $type     = ' ';
  205.             }
  206.         }
  207.         $strAttribute     = ' ';
  208.         if ($binary) {
  209.             $strAttribute = 'BINARY';
  210.         }
  211.         if ($unsigned) {
  212.             $strAttribute = 'UNSIGNED';
  213.         }
  214.         if ($zerofill) {
  215.             $strAttribute = 'UNSIGNED ZEROFILL';
  216.         }
  217.         if (!isset($row['Default'])) {
  218.             if ($row['Null'] != '' && $row['Null'] != 'NO') {
  219.                 $row['Default'] = '<i>NULL</i>';
  220.             }
  221.         } else {
  222.             $row['Default'] = htmlspecialchars($row['Default']);
  223.         }
  224.         $field_name = htmlspecialchars($row['Field']);
  225.         ?> 
  226. <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
  227.     <td nowrap="nowrap">
  228.         <?php
  229.         if (isset($pk_array[$row['Field']])) {
  230.             echo '<u>' . $field_name . '</u>';
  231.         } else {
  232.             echo $field_name;
  233.         }
  234.         ?> 
  235.     </td>
  236.     <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
  237. <?php /*    <td<?php echo $type_nowrap; ?>><?php echo $strAttribute; ?></td>*/ ?>
  238.     <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?></td>
  239.     <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
  240. <?php /*    <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
  241.         <?php
  242.         if ($have_rel) {
  243.             echo '    <td>';
  244.             if (isset($res_rel[$field_name])) {
  245.                 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
  246.             }
  247.             echo '</td>' . "\n";
  248.         }
  249.         if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
  250.             echo '    <td>';
  251.             if (isset($comments[$field_name])) {
  252.                 echo htmlspecialchars($comments[$field_name]);
  253.             }
  254.             echo '</td>' . "\n";
  255.         }
  256.         if ($cfgRelation['mimework']) {
  257.             $mime_map = PMA_getMIME($db, $table, true);
  258.  
  259.             echo '    <td>';
  260.             if (isset($mime_map[$field_name])) {
  261.                 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  262.             }
  263.             echo '</td>' . "\n";
  264.         }
  265.         ?>
  266. </tr>
  267.         <?php
  268.     } // end while
  269.     PMA_DBI_free_result( $result );
  270.     $count++;
  271.     ?> 
  272. </table>
  273. </div>
  274.     <?php
  275. } //ends main while
  276.  
  277. /**
  278.  * Displays the footer
  279.  */
  280. ?> 
  281. <script type="text/javascript" language="javascript">
  282. //<![CDATA[
  283. function printPage()
  284. {
  285.     document.getElementById('print').style.visibility = 'hidden';
  286.     // Do print the page
  287.     if (typeof(window.print) != 'undefined') {
  288.         window.print();
  289.     }
  290.     document.getElementById('print').style.visibility = '';
  291. }
  292. //]]>
  293. </script>
  294. <?php
  295. echo '<br /><br /><input type="button" id="print" value="' . $strPrint . '" onclick="printPage()" />';
  296.  
  297. require_once('./libraries/footer.inc.php');
  298. ?>
  299.